/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.xtandemparser.xmlreader.operations.xmlextractor;

import com.compomics.xtandemparser.xmlreader.operations.parser.options.XMLPARSINGOPTION;
import java.io.File;
import java.io.RandomAccessFile;

/**
 *
 * @author Kenneth
 */
public class XmlExtractor {

    private static File xmlFile;

    public XmlExtractor(File xmlFile) {
        XmlExtractor.xmlFile = xmlFile;
    }

    public String getXMLEntry(long startingPosition, XMLPARSINGOPTION option) {
        StringBuilder XMLEntry = new StringBuilder();
        try {
            RandomAccessFile raf = new RandomAccessFile(xmlFile, "rw");
            raf.seek(startingPosition);
            String line;
            while (true) {
                line = raf.readLine();
                XMLEntry.append(line);
                if (line.equalsIgnoreCase("</" + option.name() + ">")) {
                    break;
                }
            }
            System.out.println(XMLEntry.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return XMLEntry.toString();
        }
    }


}
